﻿using System;
using System.Collections.Generic;
using System.Text;

namespace RaisingStudio.Data.Expressions
{
    [Serializable]
    public class SortingExpression
    {
        private string columnName;
        public string ColumnName
        {
            get
            {
                return this.columnName;
            }
            set
            {
                this.columnName = value;
            }
        }

        private SortingDirection sortingDirection;
        public SortingDirection SortingDirection
        {
            get
            {
                return this.sortingDirection;
            }
            set
            {
                this.sortingDirection = value;
            }
        }
                 
        #region Constructor
        public SortingExpression()
        {
        }

        public SortingExpression(string columnName)
        {
            this.columnName = columnName;
        }

        public SortingExpression(string columnName, SortingDirection sortingDirection)
        {
            this.columnName = columnName;
            this.sortingDirection = sortingDirection;
        }

        public SortingExpression(ColumnExpression columnExpression)
        {
            this.columnName = (string)columnExpression;
        }

        public SortingExpression(ColumnExpression columnExpression, SortingDirection sortingDirection)
        {
            this.columnName = (string)columnExpression;
            this.sortingDirection = sortingDirection;
        }
        #endregion
        #region 符重载
        public static SortingExpression operator !(SortingExpression sortingExpression)
        {
            if (sortingExpression.SortingDirection == SortingDirection.Ascending)
            {
                sortingExpression.SortingDirection = SortingDirection.Descending;
            }
            else
            {
                sortingExpression.SortingDirection = SortingDirection.Ascending;
            }
            return sortingExpression;
        }
        #endregion
    }
}
